<?php 

            include './head_index.php';
            $gid=isset($_GET['gid'])?$_GET['gid']:0;
            if($gid==0) header('location:./index.php');

            $sql="select * from ".PIX."goods where id={$gid}";
            $result = mysqli_query($link,$sql);

            if(mysqli_affected_rows($link) >0){

                $row = mysqli_fetch_assoc($result);
            }
            
            $sql="select * from ".PIX."category where id ={$row['cateid']}";
            $result = mysqli_query($link,$sql);

            if(mysqli_affected_rows($link) >0){ 

                $cateres = mysqli_fetch_assoc($result);
            }
            
            $cateres=ltrim($cateres['path'].$cateres['id'],'0,');

            $sql="select * from ".PIX."category where id in( {$cateres} )";
            $result = mysqli_query($link,$sql);

            if(mysqli_affected_rows($link) >0){

                while($cateres = mysqli_fetch_assoc($result)){
                    $mianbao[] =$cateres;
                }
            }

            mysqli_free_result($result);

            $num=isset($_GET['num'])?$_GET['num'] : 0;

            $num=max($num , 1);
            $num=min($num , $row['store']);

            $sqlviews="insert into ".PIX."goods_views (`id`) values({$gid})";

            mysqli_query($link,$sqlviews);

            $sqlviews2="select count(*) ll from ".PIX."goods_views where id={$gid}";
            $resultv = mysqli_query($link,$sqlviews2);
            $liulan=mysqli_fetch_assoc($resultv)['ll'];
   
?>

        <div class="width"> <!--详情最外层-->
            <div class="fl width"> <!--面包屑开始-->
                <div class="fl detailbread">
                    <?php foreach ($mianbao as $key => $value):?>
                    <a href="./showgoods.php"><?= $value['name'] ?></a> >>
                    <?php endforeach; echo $row['goodsname']?>
                </div>
            </div><!--面包屑结束-->
           
            <div class="detailimg fl width"><!--bigimg-->
                <img src="../Commen/goodspic/m_<?= $row['goodspic'];?>"/>
            </div><!--bigimg-->

            <div class="detailgoods fr"> <!--detailgoods-->
                <div class="detailgoodsname"><b><?= $row['goodsname'];?></b></div>
                <div class="detailgoodsprice">&yen; <?= $row['price']; ?>万</div>
                <div class="detailgoodsxing">评分：
                    <div class="xingxing "></div>
                    <div class="xingxing "></div>
                    <div class="xingxing "></div>
                    <div class="xingxing "></div>
                    <div class="xingxing "></div>
                </div>
                <div class="detailgoodsxing">浏览量：<?= $liulan;?></div>
                <div class="detailgoodsxing">库存：<?= $row['store'];?></div>
                <div class="detailgoodsxing">销量：<?= $row['sale'];?></div>
                    
                <div class="buy">
                    <div class="detailgoodsxing">
                        数量：
                            <span style="border:1px solid #ccc;"><a href="?gid=<?= $row['id']?>&num=<?= $num - 1 ;?>">一</a></span>
                            <input class="detailinp" readonly type="text" name="num" value="<?= $num;?>"/>
                            <span style="border:1px solid #ccc;"><a href="?gid=<?= $row['id']?>&num=<?= $num + 1 ;?>">十</a></span>
                    </div>
                        <?php if($row['store']< 1) :?>
                        <div class="detailoninp" style="background:#FFD3EA;color:#F10582;border: 1px solid #FFD3EA;">库存已售完</div>
                        <?php else:?>                
                        <a href="doAction.php?a=shopcar&gid=<?= $gid;?>&num=<?= $num;?>" class="detailoninp">加入购物车</a>
                        <?php endif;?>
                </div>


            <div class="fl">
                <img src="./public/img/2015-01-17_183535.png"/>
            </div>
            </div><!--detailgoods-->

            <!--商品评论开始-->
          <div class="fl width" style="margin-bottom: 20px ;">
            <ul class="width fl commentbg">
                    <li class="fl ml" style="margin-bottom: 10px;"><b>累计评论</b></li>
                    <li class="fl ml"><b>详情</b></li>
                </ul>
            </div><!--商品评论结束-->
            
            <?php

                
                

                $sql="select * from ".PIX."goods_message where gid={$gid}";
                $result=mysqli_query($link,$sql);
                $message=[];
                if(mysqli_affected_rows($link) >0){
                    while($row5=mysqli_fetch_assoc($result)){
                        $message[]=$row5;
                    }
                }

                $score=['','★','★★','★★★','★★★★','★★★★★',];
            ?>

            <?php foreach ($message as $key => $val5): ?>
                <?php
                        $sql="select * from ".PIX."orders_detail where id={$val5['did']}";
                        // echo $sql;die;
                        $result=mysqli_query($link,$sql);
                        if(mysqli_affected_rows($link) >0){
                            $row6=mysqli_fetch_assoc($result);
                }
                        $sql="select * from ".PIX."orders where id={$row6['oid']}";
                             $result=mysqli_query($link,$sql);
                              if(mysqli_affected_rows($link) >0){
                                     $name=mysqli_fetch_assoc($result)['name'];
                                }
                             $sql="select * from ".PIX."orders_detail where id={$message[$key]['did']}";
                             $result=mysqli_query($link,$sql);
                              if(mysqli_affected_rows($link) >0){
                                     $status=mysqli_fetch_assoc($result);
                                }

                                if($status['status'] == 2):
                ?>
            <div class="fl width" style="margin-bottom: 20px ;background: #FFA7D3;">
            <ul class="width fl commentbg" style="background: #FFA7D3;">
                    <li class="fl ml" style="margin-bottom: 10px;"><b>订单编号：<?= $val5['did']?></b></li>
                    <li class="fl ml"><b style="margin-left: 20px;">评论者:<?= $name?></b></li>
                    <li class="fl ml"><b style="margin-left: 20px;">购买件数:<?= $status['nums']?></b></li>
                    <li class="fl ml"><b style="margin-left: 20px;">评分:<?= $score[ $message[$key]['score'] ]?></b></li>
                    <p style="float: right;">评论内容：<?= $message[$key]['content']?>

                    <?php if($message[$key]['messagepic'] !=''):?>

                    <span style="display: inline;" class="s_div"><img class="s_pic" src="./order/messagepic/s_<?= $message[$key]['messagepic']?>" alt=""><img class="m_pic" src="./order/messagepic/m_<?= $message[$key]['messagepic']?>" alt="">
                    </span>

                    <?php endif;?>


                    </p>
                </ul>
            </div>
        <?php endif;?>
            <?php endforeach;?>



            <div class="fl width"> <!--商品信息-->
                <ul class="width fl commentbg">
                    <li class="fl ml"><b>商品详情</b></li>
                </ul>

                <dl class="goodsxinxi">
                    <dd>
                        <dt><b></b></dt>
                        <b>TIPS:</b>
                        <p>1. 选购时，请综合参考尺码表中各项参数，有助于你选择到更合适的尺码。</p>
                        <p>2.（只适用服装）平铺测量自己的合身服装尺寸作参考，对比选购更准确！</p>
                        <p>请放心挑选尺码，唯品7天退货无忧替你保驾护航。</p>
                    </dd>
                    <dd>
                        <b>商品尺码</b>
                        <p><img src="./public/img/2015-01-20_155114.jpg"/></p>
                    </dd>
                    <dd>
                    <b>商品都是正品吗？</b>
                    <p>请你放心，唯品会www.vip.com上所售卖的商品均经过品牌授权，确保正品，并由中国太平洋财产保险股份有限公司为你购买的每一件商品进行承保。</p>
                    <b>尺码表上的尺码标准吗？</b>
                    <p>唯品会所售商品尺寸均为人工测量，可能会存在1-2cm的正常误差范围。</p>
                    <b>图片颜色和实物颜色是否相同？</b>
                    <p>唯品会所有商品均采用专业拍摄，力求将最真实的信息传达至你的视线。但由于个人显示器不同，可能导致实物与图片存在色差，最终颜色以实物为准。</p>
                    <b>为什么我收到的商品包装和图片显示的不一致？</b>
                    <p>由于部分商品生产批次不一，你收到货品的包装有可能与网站上图片不完全一致，但唯品会保证所售商品均为正品，商品包装请以实物为准。</p>
                    <b>网站上显示的参考价和实体店的售价一致吗？</b>
                    <p>唯品会的参考价采集自品牌官网标价、专柜标价或由品牌供应商提供。由于地区或时间的差异性，可能与你购物时的参考价不一致。唯品会网站标注的参考价仅供你参考，不作为购物依据。</p>
                    <b>如何何退货？</b>
                    <p>你签收商品之日起的7天之内，商品未经穿着不影响二次销售的情况下，唯品会为你提供七天无理由放心退服务。</p>
                    <b>退货流程如下：</b>
                    <p><img src="./public/img/goods_return_img_v1.png"/></p>
                </dd>
            </dl>



        </div><!--商品信息结束-->
        
        <div class="clear"></div>
    </div> <!--详情最外层-->
    

<?php include './footer_index.php'?>
